package com.exam.servlet;

import java.io.IOException;
import java.lang.reflect.Method;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *  基本servlet 
 *  
 *  反射
 *  反射对象中的所有方法 ----》找 hello方法
 *  方法.invoke(对象,参数)
 * 
 *
 */
public class BaseServlet extends HttpServlet {
	
	@Override
	public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//你想执行的方法
		String m = req.getParameter("m");   // add, findall
		
		// 当前对象---方法
		try {
			Method method= this.getClass().getDeclaredMethod(m, HttpServletRequest.class,HttpServletResponse.class);
			method.invoke(this, req,resp);  // 方法运行了
		
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
		 
}
